﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Milan.Windows
{
	[ComImportAttribute()]
	[GuidAttribute("000214F9-0000-0000-C000-000000000046")]
	[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
	public interface IShellLinkW
	{
		//[helpstring("Retrieves the path and filename of a shell link object")]
		void GetPath( [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, ref kernel32.WIN32_FIND_DATA pfd, uint fFlags);

		//[helpstring("Retrieves the list of shell link item identifiers")]
		void GetIDList(out IntPtr ppidl);

		//[helpstring("Sets the list of shell link item identifiers")]
		void SetIDList(IntPtr pidl);

		//[helpstring("Retrieves the shell link description string")]
		void GetDescription( [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxName);
      
		//[helpstring("Sets the shell link description string")]
		void SetDescription( [MarshalAs(UnmanagedType.LPWStr)] string pszName);

		//[helpstring("Retrieves the name of the shell link working directory")]
		void GetWorkingDirectory( [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);

		//[helpstring("Sets the name of the shell link working directory")]
		void SetWorkingDirectory( [MarshalAs(UnmanagedType.LPWStr)] string pszDir);

		//[helpstring("Retrieves the shell link command-line arguments")]
		void GetArguments( [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);

		//[helpstring("Sets the shell link command-line arguments")]
		void SetArguments( [MarshalAs(UnmanagedType.LPWStr)] string pszArgs);

		//[propget, helpstring("Retrieves or sets the shell link hot key")]
		void GetHotkey(out short pwHotkey);
		//[propput, helpstring("Retrieves or sets the shell link hot key")]
		void SetHotkey(short pwHotkey);

		//[propget, helpstring("Retrieves or sets the shell link show command")]
		void GetShowCmd(out uint piShowCmd);
		//[propput, helpstring("Retrieves or sets the shell link show command")]
		void SetShowCmd(uint piShowCmd);

		//[helpstring("Retrieves the location (path and index) of the shell link icon")]
		void GetIconLocation( [Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon);
      
		//[helpstring("Sets the location (path and index) of the shell link icon")]
		void SetIconLocation( [MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);

		//[helpstring("Sets the shell link relative path")]
		void SetRelativePath( [MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);

		//[helpstring("Resolves a shell link. The system searches for the shell link object and updates the shell link path and its list of identifiers (if necessary)")]
		void Resolve( IntPtr hWnd, uint fFlags);

		//[helpstring("Sets the shell link path and filename")]
		void SetPath( [MarshalAs(UnmanagedType.LPWStr)] string pszFile);
	}

	public enum EShellLinkGP : uint
	{
		SLGP_SHORTPATH = 1,
		SLGP_UNCPRIORITY = 2
	}

	#region Enumerations
	/// <summary>
	/// Flags determining how the links with missing
	/// targets are resolved.
	/// </summary>
	[Flags]
	public enum EShellLinkResolveFlags : uint
	{
		/// <summary>
		/// Allow any match during resolution.  Has no effect
		/// on ME/2000 or above, use the other flags instead.
		/// </summary>
		SLR_ANY_MATCH = 0x2,
		/// <summary>
		/// Call the Microsoft Windows Installer. 
		/// </summary>
		SLR_INVOKE_MSI = 0x80,
		/// <summary>
		/// Disable distributed link tracking. By default, 
		/// distributed link tracking tracks removable media 
		/// across multiple devices based on the volume name. 
		/// It also uses the UNC path to track remote file 
		/// systems whose drive letter has changed. Setting 
		/// SLR_NOLINKINFO disables both types of tracking.
		/// </summary>
		SLR_NOLINKINFO = 0x40,
		/// <summary>
		/// Do not display a dialog box if the link cannot be resolved. 
		/// When SLR_NO_UI is set, a time-out value that specifies the 
		/// maximum amount of time to be spent resolving the link can 
		/// be specified in milliseconds. The function returns if the 
		/// link cannot be resolved within the time-out duration. 
		/// If the timeout is not set, the time-out duration will be 
		/// set to the default value of 3,000 milliseconds (3 seconds). 
		/// </summary>                                  
		SLR_NO_UI = 0x1,
		/// <summary>
		/// Not documented in SDK.  Assume same as SLR_NO_UI but 
		/// intended for applications without a hWnd.
		/// </summary>
		SLR_NO_UI_WITH_MSG_PUMP = 0x101,
		/// <summary>
		/// Do not update the link information. 
		/// </summary>
		SLR_NOUPDATE = 0x8,
		/// <summary>
		/// Do not execute the search heuristics. 
		/// </summary>                                                        
		SLR_NOSEARCH = 0x10,
		/// <summary>
		/// Do not use distributed link tracking. 
		/// </summary>
		SLR_NOTRACK = 0x20,
		/// <summary>
		/// If the link object has changed, update its path and list 
		/// of identifiers. If SLR_UPDATE is set, you do not need to 
		/// call IPersistFile::IsDirty to determine whether or not 
		/// the link object has changed. 
		/// </summary>
		SLR_UPDATE = 0x4
	}

	public enum LinkDisplayMode : uint
	{
		edmNormal = user32.EShowWindowFlags.SW_NORMAL,
		edmMinimized = user32.EShowWindowFlags.SW_SHOWMINNOACTIVE,
		edmMaximized = user32.EShowWindowFlags.SW_MAXIMIZE
	}
	#endregion

}
